/**
 * @param {number} N
 * @return {number}
 */
var clumsy = function (N) {
  if (N == 0) {
    return 0;
  }
  if (N == 1) {
    return 1;
  }
  if (N == 2) {
    return 2;
  }

  let res = N - 3;
  const dfs = (index) => {
    if (index <= 0) {
      return 0;
    }
    if (index == 1) {
      return 1;
    }
    if (index == 2) {
      return 2;
    }
    if (index == 3) {
      return 6;
    }
    res += index - 3;
    return Math.floor((index * (index - 1)) / (index - 2)) + dfs(index - 4);
  };

  return Math.floor((N * (N - 1)) / (N - 2)) - dfs(N - 4) + res;
};
